import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path:"/",
    redirect:"/login"
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue'),
    meta:{
      isShow:false,
    },
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/user/user.vue'),
    redirect:"/user/main",
    meta:{
      isShow:true,
    },
    children:[
      {
        path: 'main',
        name: 'main',
        component: () => import('../views/user/main.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'phone',
        name: 'phone',
        component: () => import('../views/user/phone.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'list',
        name: 'list',
        component: () => import('../views/user/list.vue'),
        meta:{
          isShow:true,
        },
      }
    ]
  },{
    path: '/shop',
    name: 'shop',
    component: () => import('../views/shop/shop.vue'),
    redirect:"/shop/shoplist",
    meta:{
      isShow:true,
    },
    children:[
      {
        path: 'shoplist',
        name: 'shoplist',
        component: () => import('../views/shop/shoplist.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'classify',
        name: 'classify',
        component: () => import('../views/shop/classify.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'goods',
        name: 'goods',
        component: () => import('../views/shop/goods.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'type',
        name: 'type',
        component: () => import('../views/shop/type.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'comment',
        name: 'comment',
        component: () => import('../views/shop/comment.vue'),
        meta:{
          isShow:true,
        },
      }
    ]
  },{
    path: '/order',
    name: 'order',
    component: () => import('../views/order/order.vue'),
    redirect:"/order/orders",
    meta:{
      isShow:true,
    },
    children:[
      {
        path: 'orders',
        name: 'orders',
        component: () => import('../views/order/orders.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'control',
        name: 'control',
        component: () => import('../views/order/control.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'after',
        name: 'after',
        component: () => import('../views/order/after.vue'),
        meta:{
          isShow:true,
        },
      }
    ]
  },{
    path: '/member',
    name: 'member',
    component: () => import('../views/member/member.vue'),
    redirect:"/member/list",
    meta:{
      isShow:true,
    },
    children:[
      {
        path: 'list',
        name: 'list',
        component: () => import('../views/member/list.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'grade',
        name: 'grade',
        component: () => import('../views/member/grade.vue'),
        meta:{
          isShow:true,
        },
      }
    ]
  },{
    path: '/set',
    name: 'set',
    component: () => import('../views/set/set.vue'),
    redirect:"/set/basic",
    meta:{
      isShow:true,
    },
    children:[
      {
        path: 'basic',
        name: 'basic',
        component: () => import('../views/set/basic.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'logistics',
        name: 'logistics',
        component: () => import('../views/set/logistics.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'admin',
        name: 'admin',
        component: () => import('../views/set/admin.vue'),
        meta:{
          isShow:true,
        },
      },{
        path: 'deal',
        name: 'deal',
        component: () => import('../views/set/deal.vue'),
        meta:{
          isShow:true,
        },
      }
    ]
  }
]

const router = new VueRouter({
  routes
});

// 路由导航守卫
router.beforeEach((to,from,next) => {
  console.log(to.path);
  if(localStorage.getItem("token")){
    next();
  }else{
    if(to.path == "/login"){
      next();
    }else{
      next("/login");
    }
  }
});

export default router
